package com.zhang.ziyan.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.api.R;
import com.zhang.ziyan.pojo.User;
import com.zhang.ziyan.service.RoleService;
import com.zhang.ziyan.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "User接口")
@RestController
@RequestMapping("api/User")
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    RoleService roleService;

    @ApiOperation("分页查")
    @PostMapping("/page")
    public R page(@RequestBody JSONObject params){


        return R.ok(userService.UserPage(params));
    }

    @ApiOperation("登录")
    @PostMapping("/login")
    public R login(@RequestBody JSONObject params){


        return R.ok(userService.Login(params));
    }

    @ApiOperation("添加")
    @PostMapping("/add")
    public R add(User user){


        return R.ok(userService.save(user));
    }
    @ApiOperation("删除")
    @PostMapping("/delete")
    public R delete(Long id){


        return R.ok(userService.removeById(id));
    }


    @ApiOperation("查角色信息权限")
    @PostMapping("/selectrolename")
    public R selectrolename(@RequestBody JSONObject params){

        Long role_id = userService.SelectRoleId(params).getLong("role_id");


        System.out.println(role_id);
        return R.ok(roleService.PermissionById(role_id));
    }



}
